<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Creates an initialization vector (IV) from a random source</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.mcrypt-cfb.html">mcrypt_cfb</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.mcrypt-decrypt.html">mcrypt_decrypt</a></div>
 <div class="up"><a href="ref.mcrypt.html">Mcrypt 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.mcrypt-create-iv" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">mcrypt_create_iv</h1>
  <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">mcrypt_create_iv</span> &mdash; <span class="dc-title">Creates an initialization vector (IV) from a random source</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.mcrypt-create-iv-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">string</span> <span class="methodname"><strong>mcrypt_create_iv</strong></span>
    ( <span class="methodparam"><span class="type">int</span> <code class="parameter">$size</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$source</code><span class="initializer"> = MCRYPT_DEV_RANDOM</span></span>
  ] )</div>

  <p class="para rdfs-comment">
   Creates an initialization vector (IV) from a random source.
  </p>
  <p class="para">
   The IV is only meant to give an alternative seed to the encryption
   routines. This IV does not need to be secret at all, though it can be
   desirable. You even can send it along with your ciphertext without
   losing security.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.mcrypt-create-iv-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">size</code></em></dt>

     <dd>

      <p class="para">
       The size of the IV.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">source</code></em></dt>

     <dd>

      <p class="para">
       The source of the IV. The source can be
       <strong><code>MCRYPT_RAND</code></strong> (system random number generator),
       <strong><code>MCRYPT_DEV_RANDOM</code></strong> (read data from
       <var class="filename">/dev/random</var>) and
       <strong><code>MCRYPT_DEV_URANDOM</code></strong> (read data from
       <var class="filename">/dev/urandom</var>). Prior to 5.3.0,
       <strong><code>MCRYPT_RAND</code></strong> was the only one supported on Windows.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.mcrypt-create-iv-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns the initialization vector, or <strong><code>FALSE</code></strong> on error.
  </p>
 </div>

 
 <div class="refsect1 changelog" id="refsect1-function.mcrypt-create-iv-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>5.3.0</td>
       <td>
        <strong><code>MCRYPT_DEV_RANDOM</code></strong> and
        <strong><code>MCRYPT_DEV_URANDOM</code></strong> became available on Windows
        platforms.
       </td>
      </tr>

      <tr>
       <td>5.3.0</td>
       <td>
        It is no longer required to call <span class="function"><a href="function.srand.html" class="function">srand()</a></span> first. This
        is now done automatically.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.mcrypt-create-iv-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-813">
    <p><strong>Example #1 <span class="function"><strong>mcrypt_create_iv()</strong></span> Example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />&nbsp;&nbsp;&nbsp;&nbsp;$size&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mcrypt_get_iv_size</span><span style="color: #007700">(</span><span style="color: #0000BB">MCRYPT_CAST_256</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">MCRYPT_MODE_CFB</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$iv&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mcrypt_create_iv</span><span style="color: #007700">(</span><span style="color: #0000BB">$size</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">MCRYPT_DEV_RANDOM</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.mcrypt-create-iv-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><a href="http://www.ciphersbyritter.com/GLOSSARY.HTM#IV" class="link external">&raquo;&nbsp;http://www.ciphersbyritter.com/GLOSSARY.HTM#IV</a></li>
    <li class="member"><a href="http://www.quadibloc.com/crypto/co0409.htm" class="link external">&raquo;&nbsp;http://www.quadibloc.com/crypto/co0409.htm</a></li>
    <li class="member">Chapter 9.3 of Applied Cryptography by Schneier (ISBN 0-471-11709-9)</li>
   </ul>
  </p>
 </div>

</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.mcrypt-cfb.html">mcrypt_cfb</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.mcrypt-decrypt.html">mcrypt_decrypt</a></div>
 <div class="up"><a href="ref.mcrypt.html">Mcrypt 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
